//
//  ShopMyInfoTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/5/18.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopMyInfoTableViewCell.h"

@interface ShopMyInfoTableViewCell()<UITextFieldDelegate>

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UITextField *textField;
@property (nonatomic,strong) UIView *shapeView;
Strong UILabel *contentLabel;

@end

@implementation ShopMyInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;

        _shapeView = [UIView new];
        _shapeView.backgroundColor = getColor(mainColor);
        _shapeView.layer.masksToBounds = YES;
        _shapeView.layer.cornerRadius = 1;
        
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15 weight:1];
        
        _textField = [UITextField new];
        _textField.delegate = self;
        _textField.font = DEF_FontSize_15;
        
        _contentLabel  = [[UILabel alloc]init];
        _contentLabel.font = DEF_FontSize_14;
        [self.contentView addSubview:_contentLabel];
        
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_textField];
        [self.contentView addSubview:_shapeView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _shapeView.frame = CGRectMake(55, 12, 5, self.height-24);
    _titleLabel.frame = CGRectMake(CGRectGetMaxX(_shapeView.frame) + 5, 0, 85, self.height);
    _textField.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame), 0, SCREEN_WIDTH - CGRectGetMaxX(_titleLabel.frame), self.height);
    _contentLabel.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame), 0, SCREEN_WIDTH - CGRectGetMaxX(_titleLabel.frame), self.height);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    NSString *str;
    if ([_dataDictionary[@"key"] isEqualToString:@"无"]) {
        str = @"";
    }else{
        str = _dataDictionary[@"key"];
    }
    
    _titleLabel.text = _dataDictionary[@"title"];
    _textField.placeholder = _dataDictionary[@"ph"];
    _textField.text = str;
    _textField.hidden = NO;
    _contentLabel.hidden = YES;
//    if (self.indexPath.row == 0) {
//        _textField.hidden = YES;
//        _contentLabel.hidden = NO;
//        NSMutableAttributedString *attStr1 = [[NSMutableAttributedString alloc]init];
//        for (int i = 0; i < 5; i ++) {
//            if (i < [dataDictionary[@"user_mark"] integerValue]) {
//                NSTextAttachment *seeAtt1 = [NSTextAttachment new];
//                seeAtt1.bounds = CGRectMake(0, -2, 15, 15);
//                seeAtt1.image = [UIImage imageNamed:@"xin_sel"];
//                [attStr1 appendAttributedString:[NSAttributedString attributedStringWithAttachment:seeAtt1]];
//            }else{
//                NSTextAttachment *seeAtt1 = [NSTextAttachment new];
//                seeAtt1.bounds = CGRectMake(0, -2, 15, 15);
//                seeAtt1.image = [UIImage imageNamed:@"xin"];
//                [attStr1 appendAttributedString:[NSAttributedString attributedStringWithAttachment:seeAtt1]];
//            }
//        }
//        _contentLabel.attributedText = attStr1;
//    }else if (self.indexPath.row == 6){
//        _textField.hidden = YES;
//        _contentLabel.hidden = NO;
//        _contentLabel.text = _dataDictionary[@"ph"];
//        _contentLabel.textColor = getColor(mainColor);
//    }else if (self.indexPath.row == 7){
//        _textField.hidden = YES;
//        _contentLabel.hidden = NO;
//        _contentLabel.text = _dataDictionary[@"key"];
//        _contentLabel.textColor = getColor(mainColor);
//    }else if (self.indexPath.row == 2){
//        _textField.hidden = YES;
//        _contentLabel.hidden = NO;
//        _contentLabel.text = str;
//        if ([_dataDictionary[@"key"] isEqualToString:_dataDictionary[@"ph"]]) {
//            _contentLabel.textColor = getColor(@"c9c9ce");
//        }else{
//            _contentLabel.textColor = getColor(@"000000");
//        }
//    }
}

#pragma mark - UITextFieldDelegate

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (_getTextString) {
        _getTextString(textField.text);
    }
}

@end
